<!DOCTYPE HTML>
<html>
<head>
	<?php
	include("include.php");
	
	//get an id
	$eventID = (empty($_GET['eventID']))?1:$_GET['eventID'];
	
	//get event from id
	$event = eventClass::getEventDetails($eventID);
	
	//get similar events, 3 of them
	$similarEvents = eventClass::getSimilarEvents($eventID, 3);
	
	
	
	//checks if the user has access to edit the event ------------------------------
	$editable = false;
	if(isset($_COOKIE['BuffBoardCookie'])){
		
		//gets the current users ID
		$userID = $_COOKIE['BuffBoardCookie'];
		
		//gets the access level of the current user
		$userLevel = userClass::getUserType($userID);
		
		//if the user is an admin, let them edit
		if($userLevel==3){
			$editable = true;
		}
		//if the user owns the event, let them edit
		else if($userID == $event['user_id']){
			$editable=true;
		}
	}
	// -----------------------------------------------------------------------------
	
	$deleteable = false;
	?>
	
	
	
</head>
<body>

<div class="container">
	<div id="header">
		<?php include("banner.php")?>
		
		<div id="login">
			<?php login::displayLoginDiv(); ?>
		</div>
		
		<div class="clear"></div>
		
		<div id="navigation">
			<?php include('navigation.php'); ?>
		</div>
	</div>
	
	<div class="clear"></div>
	
	<div id="body">
		<div id="content">
			
			<!---------------------------------------------------------------
				Edit Div
				This contains the register, edit, and delete buttons
			 ---------------------------------------------------------------->
			<div id="edit" style="margin:10px 10px; float:right;">
			
				<form action="event" method="post" name="registerForm" style="display:none;">
					<!-- Bri's stuff -->
				</form>
			
				<a href="javascript: void(0);" onclick="document.registerForm.submit();returnfalse;">Register For Event</a>
				
				<?php if($editable) {?>
					<form action="editevent.php" method="post" name="editForm" style="display:none;">
						<input type="hidden" name="eventID" value="<?php echo $eventID;?>"/>
						<input type="submit" value="Edit" />
					</form>
				
					&bull;
					<a href="javascript: void(0);" onclick="document.editForm.submit();returnfalse;">Edit</a>
				<?php }?>
				
				<?php if($deleteable){ ?>
					<form name="deleteForm" style="display:none;">
						<!-- Bri's stuff -->
					</form>
				
					&bull;
					<a href="javascript: void(0);" onclick="document.deleteForm.submit();returnfalse;">Delete</a>
				<?php } ?>
				
			</div>
			
			<div id="event">
				<h1><?php echo $event['name']; ?></h1>
				
				<img src="<?php echo $event['image_path'];?>" />
				
				<p>Location: <?php echo $event['location']; ?></p>
				<p>When: <?php echo ourDate::formatDate($event['start_time']); ?></p>
				<p>Hosted by: <?php echo $event['hosted_by']; ?></p>
				
				<p>Description: <?php echo $event['description']; ?></p>
				
				<?php if(!empty($event['LINK'])){?>
				<p>Link: <a href="<?php echo $event['link'];?>"><?php echo $event['link'];?></a></p>
				<?php } ?>
					
				<p>Tags:
				<?php 
				$tags = array();
				foreach($event['tags'] as $key => $tag){
					$tags[] = '<a href="search.php?id='.$tag['id'].'">'.$tag['name'].'</a>';
				}
				echo implode(", ", $tags); ?>
				
				</p>
			</div>
			
			<div class="clear"></div>
			
			<!-- similar events -->
			<fieldset>
				<legend>Similar Events</legend>
				
				<?php foreach($similarEvents as $ID => $event)
				{
				?>
					<div class="similarEvent">
					<img src="<?php echo $event['image_path']; ?>" />
						<h2><a href="event.php?eventID=<?php echo $ID;?>"><?php echo $event['name']; ?></a></h2>
						<p><?php echo $event['location']; ?></p>
						<p><?php echo ourDate::formatDate($event['start_time']); ?></p>
						<p><?php echo substr($event['description'], 0, 60)." . . .";?></p>
					</div>
				<?php 
				} ?>
				
			</fieldset>
			
		</div>
		<div id="tags">
			<h1>Tags</h1>
			<?php tag::displayTagCloud(); ?>
		</div>
		
		<div id="fblike">
			<?php include "facebookLike.php"; ?>
        </div>
	
	</div>
	
	<div class="clear"></div>
	
	<div id="footer">
		<?php include("footer.php"); ?>
	</div>

</div>


</body>
</html>